import http from "../utils/request";
const api = {
  getCameraVideo: {
    url: "http://183.6.88.43:8008/Safe/video_feed",
    method: "get",
  },
  get_detect_info: {
    url: "http://183.6.88.43:8007/Safe/get_detect_info",
    method: "post",
  },
  get_statistics_info: {
    url: "http://183.6.88.43:8007/Safe/get_statistics_info",
    method: "post",
  },
  getStatistic: { method: "get" },
  updateInfo: {
    url: "http://183.6.88.43:8007/Safe/update_info",
    method: "post",
    data: {
      id: "",
      is_read: "",
      remark: "",
    },
  },
  set_camera_number: {
    des: "切换当前摄像头时候用于保存信息",
    url: "http://183.6.88.43:8007/Safe/set_camera_number",
    method: "post",
    data: {
      camera_name: "C1",
      timestamp: "123456789",
    },
  },
};
/**
 *
 * @param {*} param { name, data }
 * @returns { method, url, data }
 */
function filter({ name, data, _url, responseType }) {
  try {
    const { method, url } = api[name];
    return { method, url: _url || url, data, responseType };
  } catch (error) {
    throw `System Error: filter[${JSON.stringify(error)}]`;
  }
}

const fetchGenoritor = async (param) => {
  try {
    return await http(filter(param));
  } catch (error) {
    console.error(`System Error :${JSON.stringify(error)}`);
  }
};
export default fetchGenoritor;
